/*
 * XMLObject.java
 *
 * Created on June 6, 2007, 11:13 AM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package org.atomojo.app.db;

import java.io.IOException;
import org.atomojo.app.client.XMLRepresentationParser;
import org.infoset.xml.Element;
import org.infoset.xml.XMLException;
import org.restlet.representation.Representation;

/**
 *
 * @author alex
 */
public abstract class XMLObject
{
   
   Element xml;
   Representation rep;
   
   /** Creates a new instance of XMLObject */
   protected XMLObject(Representation rep)
   {
      this.rep = rep;
      this.xml = null;
   }
   
   protected XMLObject(Element xml)
   {
      this.rep = null;
      this.xml = xml;
   }
   
   public void parse() 
      throws IOException,XMLException
   {
      XMLRepresentationParser parser = new XMLRepresentationParser();
      xml = parser.load(getRepresentation()).getDocumentElement();
   }
   
   public Element getElement() 
   {
      return xml;
   }
   
   public Representation getRepresentation() {
      return rep;
   }
   
   public abstract void unmarshall()
      throws XMLException;
   
   public abstract void marshall()
      throws XMLException;
   
}
